package com.topscore.uke.mvp.model;

import com.topscore.uke.entities.DistrictBean;
import com.topscore.uke.mvp.contractors.GetDistrictInfoContractor;
import com.topscore.uke.network.BaseResponse;
import com.topscore.uke.network.retrofit.HandleErrorSubscriber;

import java.util.List;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by 71468 on 2017/11/21.
 */

public class GetDistrictInfoModel implements GetDistrictInfoContractor, GetDistrictInfoContractor.Model {
    private CallBack mCallBack;

    public GetDistrictInfoModel(CallBack callBack) {
        this.mCallBack = callBack;
    }

    @Override
    public void getDistrict(String cityId) {
        mService.getDistrictInfo(cityId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<List<DistrictBean>>>(mCallBack) {
                    @Override
                    public void onSuccess(BaseResponse<List<DistrictBean>> response) {
                        mCallBack.onSuccess(response);
                    }
                });
    }
}
